<template>
	<view class="box">
		<view class="title" :style="{ 'border-top': systemBarHeight * 2 + 'rpx solid rgba(0, 32, 68, 0.5)' }">
			<view class="left_btn" @click="goBack()"></view>
			<view class="txt">秦创原（宝鸡）创新公共服务平台</view>
		</view>
		<view class="count" :style="{ 'margin-top': systemBarHeight * 2 + 'rpx' }">
			<view class="count_list" v-for="(item, index) in statisticsArr" :key="index">
				<view class="icon kcbss" v-if="item.label === '科技人才'"></view>
				<view class="icon zpxx" v-if="item.label === '专利'"></view>
				<view class="icon qzxx" v-if="item.label === '科技园区'"></view>
				<view class="icon wxfw" v-if="item.label === '文献服务'"></view>
				<view class="icon kjcx" v-if="item.label === '揭榜挂帅'"></view>
				<view class="icon cxpt" v-if="item.label === '创新平台'"></view>
				<view class="icon qyyh" v-if="item.label === '成果'"></view>
				<view class="icon gryh" v-if="item.label === '可转化成果'"></view>
				<view class="right">
					<view class="count_title">{{ item.label }}</view>
					<view class="num">
						{{ item.value }}
						<text>{{ item.unit }}</text>
					</view>
				</view>
			</view>
		</view>
		<view class="active_data">
			<view class="active_data_name">当前数据：</view>
			<view class="active_data_select">
				<easy-select
					ref="easySelect"
					style="width: 200rpx; height: 100%"
					@click="cityToggleBtn()"
					class="easy_select"
					:options="options"
					size="mini"
					:value="selecValue"
					@selectOne="selectOne"
				></easy-select>
				<!-- <text>全部地市</text>
				<view class="active_data_icon"></view> -->
			</view>
		</view>
		<view class="echart">
			<view class="echart_item">
				<view class="echart_item_title">
					<view class="echart_item_icon"></view>
					<view class="echart_item_name">科技成果</view>
				</view>
				<view class="echart_box">
					<kjcg-chart ref="kjcg" :code="code"></kjcg-chart>
				</view>
			</view>
			<view class="echart_item">
				<view class="echart_item_title">
					<view class="echart_item_icon"></view>
					<view class="echart_item_name">科技人才</view>
				</view>
				<view class="echart_box">
					<kjrc-chart ref="kjrc" :code="code"></kjrc-chart>
				</view>
			</view>
			<view class="echart_item">
				<view class="echart_item_title">
					<view class="echart_item_icon"></view>
					<view class="echart_item_name">科技企业</view>
				</view>
				<view class="echart_box">
					<kjqy-chart ref="kjqy" :code="code"></kjqy-chart>
				</view>
			</view>
			<view class="echart_item">
				<view class="echart_item_title">
					<view class="echart_item_icon"></view>
					<view class="echart_item_name">创新创业载体</view>
				</view>
				<view class="echart_box">
					<cxcyzt-chart ref="cxcyzt" :code="code"></cxcyzt-chart>
				</view>
			</view>
			<view class="echart_item">
				<view class="echart_item_title">
					<view class="echart_item_icon"></view>
					<view class="echart_item_name">需求统计</view>
				</view>
				<view class="echart_box">
					<xqtj-chart ref="xqtj" :code="code"></xqtj-chart>
				</view>
			</view>
			<view class="echart_item">
				<view class="echart_item_title">
					<view class="echart_item_icon"></view>
					<view class="echart_item_name">技术合同</view>
					<view class="echart_item_num">
						<view class="mySelect" @click="open = !open">
							<view class="optionsSpan">{{ formatterYear(selectValue) }}</view>
							<u-icon :name="activeIcon"></u-icon>
							<view v-if="open" class="options">
								<view class="optionsDiv">
									<view class="optionsBtn" @click="select(item)" v-for="(item, index) in selectOptions" :key="index">
										{{ item }}
									</view>
								</view>
							</view>
						</view>
					</view>
				</view>
				<view class="echart_box">
					<jsht-chart ref="jsht" :code="code"></jsht-chart>
				</view>
			</view>
			<view class="echart_item">
				<view class="echart_item_title">
					<view class="echart_item_icon"></view>
					<view class="echart_item_name">创新平台</view>
				</view>
				<view class="echart_box">
					<cxpt-chart ref="cxpt" :code="code"></cxpt-chart>
				</view>
			</view>
			<view class="echart_item">
				<view class="echart_item_title">
					<view class="echart_item_icon"></view>
					<view class="echart_item_name">科研仪器</view>
				</view>
				<view class="echart_box">
					<kyyq-chart ref="kyyq" :code="code"></kyyq-chart>
				</view>
			</view>
			<view class="echart_item">
				<view class="echart_item_title">
					<view class="echart_item_icon"></view>
					<view class="echart_item_name">专利信息</view>
				</view>
				<view class="echart_box">
					<zlxx-chart ref="zlxx" :code="code"></zlxx-chart>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import kjcgChart from '@/pages/largeDataScreenEcharts/kjcg.vue';
import jshtChart from '@/pages/largeDataScreenEcharts/jsht.vue';
import kjqyChart from '@/pages/largeDataScreenEcharts/kjqy.vue';
import kjrcChart from '@/pages/largeDataScreenEcharts/kjrc.vue';
import cxcyztChart from '@/pages/largeDataScreenEcharts/cxcyzt.vue';
import cxptChart from '@/pages/largeDataScreenEcharts/cxpt.vue';
import kyyqChart from '@/pages/largeDataScreenEcharts/kyyq.vue';
import xqtjChart from '@/pages/largeDataScreenEcharts/xqtj.vue';
import zlxxChart from '@/pages/largeDataScreenEcharts/zlxx.vue';
import {
	listSURVEY,
	listRECRUIT,
	getTWANTEDList,
	listWXJS,
	listKJCX,
	getJbgsAllList,
	getCXPT,
	getMemNumber,
	listCGZHXM,
	getKjcgList,
	getList,
	getPatentCensusList,
	getKJYQList
} from '@/api/zhyp/statistics';

export default {
	data() {
		return {
			statisticsArr: [],
			systemBarHeight: '',
			selecValue: '全部地市',
			code: '6103',
			year: '2022',
			selectOptions: [2023, 2022, 2021],
			selectValue: 2022,
			open: false,
			activeIcon: 'arrow-down',
			options: [
				{
					value: '6103',
					label: '全部地市'
				},
				{
					value: '610302',
					label: '渭滨区'
				},
				{
					value: '610303',
					label: '金台区'
				},
				{
					value: '610304',
					label: '陈仓区'
				},
				{
					value: '610322',
					label: '风翔区'
				},
				{
					value: '610323',
					label: '岐山县'
				},
				{
					value: '610324',
					label: '扶风县'
				},
				{
					value: '610326',
					label: '眉县'
				},
				{
					value: '610327',
					label: '陇县'
				},
				{
					value: '610328',
					label: '千阳县'
				},
				{
					value: '610329',
					label: '麟游县'
				},
				{
					value: '610330',
					label: '凤县'
				},
				{
					value: '610331',
					label: '太白县'
				}
			],
			chartList: ['kjcg', 'kjrc', 'kjqy', 'cxcyzt', 'xqtj', 'jsht', 'cxpt', 'kyyq', 'zlxx']
		};
	},
	components: {
		kjcgChart,
		jshtChart,
		kjqyChart,
		kjrcChart,
		cxcyztChart,
		cxptChart,
		kyyqChart,
		xqtjChart,
		zlxxChart
	},
	created() {
		this.getBeforeYears();
		this.getSysteminfo();
		this.getStatistics();
	},
	watch: {
		open(val) {
			if (val) {
				this.activeIcon = 'arrow-up';
			} else {
				this.activeIcon = 'arrow-down';
			}
		}
	},
	methods: {
		formatterYear(val) {
			return val + '年';
		},
		// 获得之前年份数组
		getBeforeYears() {
			console.log(999);
			var now = new Date();
			var years = [];
			for (var i = 0; i < 10; i++) {
				years.push(now.getFullYear() - i);
			}
			this.selectOptions = years;
		},
		select(item) {
			this.selectValue = item;
			this.$refs.jsht.searchValue = item
			this.$refs.jsht.getData()
		},
		selectOne(options) {
			this.selecValue = options.label;
			this.code = options.value;
			this.getStatistics();
			this.chartList.forEach((item) => {
				this.$refs[item].code = options.value;
				this.$refs[item].getData();
			});
		},
		// 切换城市
		cityToggleBtn() {
			this.$refs.easySelect.hideOptions && this.$refs.easySelect.hideOptions();
		},
		// 返回上一页
		goBack() {
			uni.navigateBack();
		},
		// 获取系统栏高度
		getSysteminfo() {
			uni.getSystemInfo({
				success: (res) => {
					this.systemBarHeight = res.statusBarHeight;
				}
			});
		},
		async getStatistics() {
			this.statisticsArr = []
			const kcbsh = await getList();
			this.statisticsArr.push({
				value: kcbsh.total || 0,
				label: '科技人才',
				unit: '人'
			});
			const zpxx = await getPatentCensusList();
			this.statisticsArr.push({
				value: zpxx.total || 0,
				label: '专利',
				unit: '个'
			});
			const qzxx = await getKJYQList({ status: '3' });
			this.statisticsArr.push({
				value: qzxx.total || 0,
				label: '科技园区',
				unit: '家'
			});
			const wxjs = await listWXJS();
			const kjcx = await listKJCX();
			this.statisticsArr.push({
				value: wxjs.total + kjcx.total,
				label: '文献服务',
				unit: '份'
			});
			const jbgs = await getJbgsAllList(data);
			this.statisticsArr.push({
				value: jbgs.total,
				label: '揭榜挂帅',
				unit: '个'
			});

			const cxpt = await getCXPT(this.code);
			let cxptNum = 0;
			cxpt.data.CXPT.forEach((item) => {
				cxptNum += item.COUNT;
			});
			this.statisticsArr.push({
				value: cxptNum,
				label: '创新平台',
				unit: '家'
			});
			const kjcgdj = await getKjcgList({ isPublish: '1' });
			this.statisticsArr.push({
				value: kjcgdj.total || 0,
				label: '成果',
				unit: '个'
			});
			const kzhcg = await listCGZHXM({ isPublish: '1' });
			this.statisticsArr.push({
				value: kzhcg.total || 0,
				label: '可转化成果',
				unit: '个'
			});
			const data = {
				status: 2,
				isShow: 0
			};
		},
		classFormat(label) {
			if (label === '科创板上市') {
				return 'kcbss';
			} else if (label === '创新平台') {
				return 'cxpt';
			} else if (label === '文献服务') {
				return 'wxfw';
			} else if (label === '揭榜挂帅') {
				return 'kjcx';
			} else if (label === '企业用户') {
				return 'qyyh';
			} else if (label === '个人用户') {
				return 'gryh';
			} else if (label === '求职信息') {
				return 'qzxx';
			} else if (label === '招聘信息') {
				return 'zpxx';
			}
		}
	}
};
</script>

<style lang="scss">
.box {
	background-color: #0c2238;
	padding-top: 88rpx;
	.title {
		position: fixed;
		z-index: 999;
		top: 0;
		width: 100%;
		height: 88rpx;
		background-image: url(/static/largeDataScreenImg/top_bg.png);
		background-size: cover;
		background-repeat: no-repeat;
		display: flex;
		color: #fff;
		font-size: 28rpx;
		font-weight: 700;
		.left_btn {
			width: 48rpx;
			height: 48rpx;
			background-image: url(/static/largeDataScreenImg/ic_goBack.png);
			background-size: cover;
			position: absolute;
			left: 32rpx;
			top: 50%;
			transform: translateY(-50%);
		}
		.txt {
			margin: auto;
		}
	}
	.count {
		display: flex;
		flex-wrap: wrap;
		padding: 36rpx 76rpx;
		justify-content: space-between;
		.count_list {
			width: 45%;
			display: flex;
			margin-bottom: 24rpx;
			.icon {
				margin-right: 4rpx;
				width: 96rpx;
				height: 96rpx;
				// background-image: url('/static/largeDataScreenImg/ic_cxpt.png');
				background-size: cover;
				&.kcbss {
					background-image: url(/static/largeDataScreenImg/ic-kcbss.png);
				}
				&.cxpt {
					background-image: url(/static/largeDataScreenImg/ic-cxpt.png);
				}
				&.kjcx {
					background-image: url(/static/largeDataScreenImg/ic-kjcx.png);
				}
				&.wxfw {
					background-image: url(/static/largeDataScreenImg/ic-wjjs.png);
				}
				&.qyyh {
					background-image: url(/static/largeDataScreenImg/ic-qyyh.png);
				}
				&.gryh {
					background-image: url(/static/largeDataScreenImg/ic-gryh.png);
				}
				&.qzxx {
					background-image: url(/static/largeDataScreenImg/ic-qzxx.png);
				}
				&.zpxx {
					background-image: url(/static/largeDataScreenImg/ic-zpxx.png);
				}
			}
			.right {
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				.count_title {
					color: rgba(255, 255, 255, 0.64);
					font-size: 28rpx;
					line-height: 44rpx;
				}
				.num {
					color: rgba(255, 255, 255, 0.87);
					font-size: 40rpx;
					font-weight: 700;
					line-height: 56rpx;
					text {
						margin-left: 8rpx;
						color: rgba(255, 255, 255, 0.64);
						font-size: 28rpx;
						line-height: 44rpx;
					}
				}
			}
		}
	}
	.active_data {
		width: 100%;
		height: 84rpx;
		background-color: rgba(0, 102, 255, 0.14);
		display: flex;
		align-items: center;
		font-size: 36rpx;
		line-height: 52rpx;
		color: rgba(255, 255, 255, 0.87);
		.active_data_name {
			margin: 0 16rpx;
		}
		.active_data_select {
			position: relative;
			display: flex;
			align-items: center;
			.easy_select {
			}
			text {
				position: relative;
			}
			.active_data_icon {
				margin-left: 16rpx;
				width: 32rpx;
				height: 32rpx;
				background-image: url(/static/largeDataScreenImg/ic_select.png);
				background-size: cover;
			}
		}
	}
	.echart {
		padding: 0 16rpx;
		.echart_item {
			margin-top: 48rpx;
			.echart_item_title {
				width: calc(100% - 16rpx);
				height: 84rpx;
				margin-left: 16rpx;
				position: relative;
				display: flex;
				align-items: center;
				justify-content: space-between;
				background-color: rgba(0, 102, 255, 0.14);
				color: rgba(255, 255, 255, 0.87);
				&::before {
					content: '';
					display: block;
					height: 100%;
					width: 8rpx;
					position: absolute;
					left: -16rpx;
					background-color: #1b7ef2;
				}
				.echart_item_icon {
					position: absolute;
					width: 32rpx;
					height: 32rpx;
					background-image: url(/static/largeDataScreenImg/ic_select.png);
					transform: rotate(-90deg);
					background-size: cover;
				}
				.echart_item_name {
					margin-left: 38rpx;
					font-size: 28rpx;
				}
				.echart_item_num {
					margin-right: 36rpx;
					font-size: 28rpx;
					font-weight: 700;
					text {
						margin-left: 8rpx;
						font-weight: normal;
					}
					.mySelect {
						position: relative;
						z-index: 100;
						cursor: pointer;
						width: 150rpx;
						height: 50rpx;
						border-radius: 8px;
						border: 1px solid rgba(151, 151, 151, 0.49);
						color: #fff;
						display: flex;
						justify-content: space-evenly;
						align-items: center;
						span {
						}
						.options {
							width: 150rpx;
							position: absolute;
							z-index: 999;
							top: 66rpx;
							right: -2rpx;
							&::before {
								position: absolute;
								top: -10rpx;
								left: 50%;
								transform: translateX(-50%) rotate(45deg);
								// background-color: #fff;
								background-color: rgba($color: #fff, $alpha: 0.2);
								content: '';
								display: block;
								width: 20rpx;
								height: 20rpx;
								z-index: -1;
							}
							> view {
								border: 1px solid rgba(151, 151, 151, 0.49);
								width: 100%;
								height: 150px;
								border-radius: 8px;
								overflow-y: auto;
								&::-webkit-scrollbar {
									width: 4px;
									height: 4px;
									border-radius: 8px;
									overflow-y: scroll;
								}
								&::-webkit-scrollbar-thumb {
									background: #101214;
								}
								&::-webkit-scrollbar-track {
									background: #354352;
								}
								view {
									background-color: #344557;
									box-sizing: border-box;
									padding: 5px;
									text-align: center;
									&:hover {
										background-color: #808b96;
									}
								}
							}
						}
					}
				}
			}
		}
	}
}
</style>
